<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style>
        .van-popup {
            background-color: transparent;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-nav-bar style="z-index: 99999;" id="navBar" title="ESOP查看">
                <template #left>
                    <van-icon name="arrow-left" color="#fff" size="17px" @click="onClickLeft"></van-icon>
                </template>
            </van-nav-bar>

            <van-popup v-model="showLoading">
                <van-loading color="#e6c678" size="40" vertical>加载中，请稍后...</van-loading>
            </van-popup>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        var pdfReader = api.require('pdfReader');

        vm = new Vue({
            el: '#app',
            data: {
                showLoading: true
            },
            created: function () {
                var that = this;
                var navBar = document.getElementById('navBar')
                navBar.style.paddingTop = api.safeArea.top + 'px'

                if (window.localStorage.getItem('clientHeight') != 752) {
                } else {
                    document.getElementById('navBar').style.fontSize = 'x-large'
                    document.getElementById('navBar').style.fontWeight = '800'
                }
                if (api.pageParam.SOP) {
                    that.getSOP()
                } else {
                    that.openPDF()
                }

                console.log('ESOP', JSON.stringify(api.pageParam))
            },
            methods: {
                getSOP() {
                    var that = this
                    pdfReader.openView({
                        path: 'http://' + window.localStorage.getItem('serverIP') + api.pageParam.SOP.FilePath,
                        rect: {
                            x: 0,
                            y: 60,
                            w: 'auto',
                            h: 'auto'
                        },
                        fixed: true,
                    });
                },
                openPDF() {
                    var that = this
                    var height = document.getElementById('navBar')
                    var obj = {
                        ProductCode: api.pageParam.ProductItem.ProductCode,
                        ProductName: api.pageParam.ProductItem.ProductName,
                    }
                    // var obj = {
                    //     ProductCode: '20101101',
                    //     ProductName: 'U717 后方杯托电镀件',
                    // }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('getProESOP', obj, function (res) {
                        // console.log('PDF.res', JSON.stringify(res))
                        that.showLoading = false
                        if (res.ds.length) {
                            pdfReader.openView({
                                path: 'http://' + window.localStorage.getItem('serverIP') + res.ds[0].FilePath,
                                rect: {
                                    x: 0,
                                    y: 60,
                                    w: 'auto',
                                    h: 'auto'
                                },
                                fixed: true,
                            });
                        } else {
                            api.toast({
                                msg: '该产品暂无作业指导书！'
                            })
                            api.closeWin();
                        }
                    })
                },
                onClickLeft() {
                    var that = this
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>